# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        博智科技  
# Name:         demo1412
# Description:
# Author:       yzl
# Date:         2019-02-09
#-------------------------------------------------------------------------------


from xml.dom.minidom import parseString
import dicttoxml
import os

d = [20,'names',
    {'name':'Bill','age':30,'salary':2000.00},
    {'name':'王军','age':40,'salary':3000},
    {'name':'John','age':20,'salary':5000},
]

# 将列表转化成 xml对象
bxml = dicttoxml.dicttoxml(d,custom_root='persons')
# 指定字符集
xml = bxml.decode('utf-8')
print(xml)
dom = parseString(xml)
print(type(dom))
prettyxml = dom.toprettyxml(indent='    ')
f = open('files/persons.xml','w',encoding='utf-8')
f.write(prettyxml)
f.close()

